import { createRouter, createWebHistory } from "vue-router";
import { App } from 'vue'
const Layout = () => import('@/layout/index.vue')
// import Layout from '@/layout/index.vue'

const routerHistory = createWebHistory()

// createWebHashHistory hash路由
// createWebHistory history路由
// createMemoryHistory 带缓存的history路由

const router = createRouter({
    history: routerHistory,
    routes: [
        {
            path: '/',
            component: Layout,
            redirect: '/home',
            children: [
                {
                    path: '/home',
                    name: 'home',
                    component: () => import('@/views/home/index.vue')
                },
                {
                    path: '/demo',
                    name: 'demo',
                    component: () => import('@/views/demo/index.vue'),
                },
                {
                    path: '/icon',
                    name: 'icon',
                    component: () => import('@/views/icon/index.vue'),
                },
            ]
        }
    ]
})

export function resetRouter(): void {
    router.getRoutes().forEach(route => {
        const { name } = route
        if (name) {
            router.hasRoute(name) && router.removeRoute(name)
        }
    })
}

export function setupRouter(app: App<Element>) {
    app.use(router)
}

export default router